<?php
	class quangcaodb
	{
		public function Add($TenQuangCao, $DiaChiQuangCao, $HinhAnh, $Rating)
		{
			$sql = "INSERT INTO `tbl_quangcao`(`TenQuangCao`, `DiaChiQuangCao`, `HinhAnh`, `Rating`) 
					VALUES ('$TenQuangCao', '$DiaChiQuangCao', '$HinhAnh', $Rating)";
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		
		public function Delete($MaQuangCao)
		{
			$sql = "DELETE FROM `tbl_quangcao` WHERE MaQuangCao = $MaQuangCao";
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		
		public function Update($MaQuangCao, $TenQuangCao, $DiaChiQuangCao, $HinhAnh, $Rating)
		{
			$sql = "UPDATE `tbl_quangcao` SET `TenQuangCao`='$TenQuangCao',`DiaChiQuangCao`='$DiaChiQuangCao', `Rating`=$Rating "; 
			if($HinhAnh != "")
				$sql .= ",`HinhAnh`='$HinhAnh' ";
			$sql .= " WHERE `MaQuangCao`=$MaQuangCao";
			echo $sql;
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
	
		public function GetList()
		{
			$sql = "SELECT * FROM `tbl_quangcao` WHERE 1";
			$data = new dataservice();
			return $data->ExecuteQuery($sql);
		}
		
		public function GetListSortByRating()
		{
			$sql = "SELECT * FROM `tbl_quangcao` WHERE 1 ORDER BY Rating DESC LIMIT 0, 6";
			$data = new dataservice();
			return $data->ExecuteQuery($sql);
		}
		
		public function GetListByID($MaQuangCao)
		{
			$sql = "SELECT * FROM `tbl_quangcao` WHERE MaQuangCao = $MaQuangCao";
			$data = new dataservice();
			return $data->ExecuteQuery($sql);
		}
	}
?>